﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FCMS.Mail.Configuration;

namespace FCMS.Mail
{
    public class SysMailMessage
    {
        /// <summary>
        /// 邮件主题
        /// </summary>
        public string Subject { get; set; }
        /// <summary>
        /// 邮件正文
        /// </summary>
        public string Body { get; set; }
        /// <summary>
        /// 接收人名称
        /// </summary>
        public string RecipientName { get; set; }
        /// <summary>
        /// 收件人Email
        /// </summary>
        public string RecipientEmailAddress { get; set; }

        public bool Send()
        {
            SmtpMail mail = new SmtpMail();
            mail.RecipientName = this.RecipientName;
            mail.AddRecipient(this.RecipientEmailAddress);//设定收件人地址（必须填写）。
            mail.Priority = "5";//设定优先级
            mail.Html = true;//设定正文是否HTML格式。
            mail.Subject = this.Subject;//设定邮件主题
            mail.Body = this.Body;//设定邮件正文

            mail.From = EmailSection.Instance.From;//设定发件人地址(必须填写)
            mail.FromName = EmailSection.Instance.DisplayName;//设定发件人姓名
            mail.MailDomain = EmailSection.Instance.Host;//设定SMTP服务器地址
            mail.MailServerUserName = EmailSection.Instance.Credential.UserName;//设定SMTP验证的用户名
            mail.MailServerPassWord = EmailSection.Instance.Credential.Password;//设定SMTP验证的密码
            //开始发送
            try
            {
                return mail.Send();
            }
            catch
            {
                throw;
            }
        }
    }
}
